package org.gd.jms.actimemq;

/**
 * The following is a very simple JMS application with multiple, concurrent, consumers and producers.
 * See the Initial Configuration guide for details on how to setup your classpath correctly.
 *
 * Things you might do after running this example:
 *
 * - Setup a broker instead of using the org.activemq.broker.impl.Main class directly
 * - Use JNDI to lookup a javax.jms.ConnectionFactory rather than creating ActiveMQConnectionFactory directly.
 * - Implement the javax.jms.MessageListener interface rather than calling consumer.receive()
 * - Use transactional sessions
 * - Use a Topic rather than a queue
 *
 * The point of this example is to show you the basic code required to use JMS in a straightforward way.
 * The Consumers and Producers could very easy be on completely different machines or in different processes.
 */
public class App {

    public static void main(String...args) throws Exception {
        thread(new HelloWorldProducer(), false);
        thread(new HelloWorldProducer(), false);
        thread(new HelloWorldProducer(), false);

        thread(new HelloWorldConsumer(), false);
        /*
        Thread.sleep(1000);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldProducer(), false);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldProducer(), false);
        Thread.sleep(1000);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldProducer(), false);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldProducer(), false);
        thread(new HelloWorldProducer(), false);
        Thread.sleep(1000);
        thread(new HelloWorldProducer(), false);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldProducer(), false);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldProducer(), false);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldProducer(), false);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldConsumer(), false);
        thread(new HelloWorldProducer(), false);*/
    }

    public static void thread(Runnable runnable, boolean daemon) {
        Thread brokerThread = new Thread(runnable);
        brokerThread.setDaemon(daemon);
        brokerThread.start();
    }
}
